<template>
<div>
  <el-dialog
    :title="title"
    :close-on-click-modal="false"
     v-dialogDrag
    :visible.sync="visible">
    <el-form :model="inputForm" size="small" ref="inputForm" v-loading="loading" :class="method==='view'?'readonly':''"  :disabled="method==='view'"
             label-width="120px">
      <el-row  :gutter="15">
        <el-col :span="12">
            <el-form-item label="设备" prop="equipmentInformation.id"
                :rules="[
                 ]">
          <GridSelect
            title="选择设备"
            labelName = 'name'
            labelValue = 'id'
            :value = "inputForm.equipmentInformation.id"
            :limit="1"
            @getValue='(value) => {inputForm.equipmentInformation.id=value}'
            :columns="[
            {
              prop: 'id',
              label: '主键'
            },
            {
              prop: 'name',
              label: '名称'
            }
            ]"
            :searchs="[
            {
              prop: 'id',
              label: '主键'
            },
            {
              prop: 'name',
              label: '名称'
            }
            ]"
            dataListUrl="/epc/equipmentinformation/equipmentInformation/list"
            entityBeanName="equipmentInformation"
            queryEntityUrl="/epc/equipmentinformation/equipmentInformation/queryById">
          </GridSelect>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="租用人名称" prop="tenantName"
                :rules="[
                 ]">
              <el-input v-model="inputForm.tenantName" placeholder="请填写租用人名称"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="租用公司名称" prop="tenantCompanyName"
                :rules="[
                 ]">
              <el-input v-model="inputForm.tenantCompanyName" placeholder="请填写租用公司名称"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="录入人" prop="dataEntryClerk.id"
                :rules="[
                 ]">
                <user-select :limit='1' :value="inputForm.dataEntryClerk.id" @getValue='(value) => {inputForm.dataEntryClerk.id=value}'></user-select>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="租用设备名称" prop="tenantDeviceName"
                :rules="[
                 ]">
              <el-input v-model="inputForm.tenantDeviceName" placeholder="请填写租用设备名称"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="租用设备数量" prop="tenantNumber"
                :rules="[
                 ]">
              <el-input v-model="inputForm.tenantNumber" placeholder="请填写租用设备数量"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="租用时间段" prop="tenantTimeQuantum"
                :rules="[
                 ]">
              <el-input v-model="inputForm.tenantTimeQuantum" placeholder="请填写租用时间段"     ></el-input>
           </el-form-item>
        </el-col>
        </el-row>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button size="small" @click="visible = false">关闭</el-button>
      <el-button size="small" type="primary" v-if="method != 'view'" @click="doSubmit()" v-noMoreClick>确定</el-button>
    </span>
  </el-dialog>
</div>
</template>

<script>
  import GridSelect from '@/components/gridSelect'
  import UserSelect from '@/components/userSelect'
  export default {
    data () {
      return {
        title: '',
        method: '',
        visible: false,
        loading: false,
        inputForm: {
          id: '',
          equipmentInformation: {
            id: ''
          },
          tenantName: '',
          tenantCompanyName: '',
          dataEntryClerk: {
            id: ''
          },
          tenantDeviceName: '',
          tenantNumber: '',
          tenantTimeQuantum: ''
        }
      }
    },
    components: {
      GridSelect,
      UserSelect
    },
    methods: {
      init (method, id) {
        this.method = method
        this.inputForm.id = id
        if (method === 'add') {
          this.title = `新建设备报修及报废`
        } else if (method === 'edit') {
          this.title = '修改设备报修及报废'
        } else if (method === 'view') {
          this.title = '查看设备报修及报废'
        }
        this.visible = true
        this.loading = false
        this.$nextTick(() => {
          this.$refs.inputForm.resetFields()
          if (method === 'edit' || method === 'view') { // 修改或者查看
            this.loading = true
            this.$http({
              url: `/epc/equipmentrepairsscrap/equipmentRepairsScrap/queryById?id=${this.inputForm.id}`,
              method: 'get'
            }).then(({data}) => {
              this.inputForm = this.recover(this.inputForm, data.equipmentRepairsScrap)
              this.loading = false
            })
          }
        })
      },
      // 表单提交
      doSubmit () {
        this.$refs['inputForm'].validate((valid) => {
          if (valid) {
            this.loading = true
            this.$http({
              url: `/epc/equipmentrepairsscrap/equipmentRepairsScrap/save`,
              method: 'post',
              data: this.inputForm
            }).then(({data}) => {
              this.loading = false
              if (data && data.success) {
                this.visible = false
                this.$message.success(data.msg)
                this.$emit('refreshDataList')
              }
            })
          }
        })
      }
    }
  }
</script>